<template>
    <div id="content">
        <div class="page-header">
            <div class="container-fluid">
                <div class="pull-right">
                    <a href="#/customer/customer_group/create"
                       data-toggle="tooltip"
                       title="" class="btn btn-primary"
                       data-original-title="添加"><i class="fa fa-plus"></i>
                    </a>
                    <button type="button" data-toggle="tooltip"
                            v-on:click="do_delete()"
                            title="" class="btn btn-danger" data-original-title="删除">
                        <i class="fa fa-trash-o"></i>
                    </button>
                </div>
                <h1>客户群组</h1>
                <ul class="breadcrumb">
                    <li><a href="#">首页</a></li>
                    <li><a href="#">客户群组</a></li>
                </ul>
            </div>
        </div>
        <div class="container-fluid">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i> 客户群组列表</h3>
                </div>
                <div class="panel-body">
                    <form action="#" method="post" enctype="multipart/form-data" id="form-customer-group">
                        <div class="table-responsive">
                            <table class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <td style="width: 1px;" class="text-center">
                                        <input type="checkbox"
                                               onclick="$('input[name*=\'selected\']').trigger('click');">
                                    </td>
                                    <td class="text-left">
                                        <a href="#" class="asc">客户群组名称</a>
                                    </td>
                                    <td class="text-right">
                                        <a href="#">排序</a>
                                    </td>
                                    <td class="text-right">操作</td>
                                </tr>
                                </thead>
                                <tbody>
                                <tr v-for="item in group_list">
                                    <td class="text-center">
                                        <input type="checkbox"
                                               v-model="del_customer_groups"
                                               v-bind:value="item.id" >
                                    </td>
                                    <td class="text-left">{{ item.name }}
                                        <b v-show="item.is_default==1">(默认)</b>
                                    </td>
                                    <td class="text-right">{{ item.sort_order }}</td>
                                    <td class="text-right">
                                        <a v-bind:href="'#/customer/customer_group/edit/'+item.id"
                                           data-toggle="tooltip" title=""
                                           class="btn btn-primary" data-original-title="编辑">
                                            <i class="fa fa-pencil"></i></a>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </form>
                    <div class="row hidden">
                        <div class="col-sm-6 text-left"></div>
                        <div class="col-sm-6 text-right">显示 1 - 1 / 合计 1（共 1 页）</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {

        data:function(){

            return {

                group_list:[],

                del_customer_groups:[]
            }

        },

        methods:{

            get_list:function(){

                var url = this.config.web_url + '/admin.php?r=customer/customer_group';
                var t = this;
                this.axios.get( url ).then(function( res ){
                    t.group_list = res.data;
                });

            },

            do_delete:function(){


                var url = this.config.web_url + '/admin.php?r=customer/customer_group/delete';
                var t = this;

                var data = "";
                for( var i = 0; i < this.del_customer_groups.length; i ++ ){
                    data += "del_customer_groups[]=" + this.del_customer_groups[i] + "&";
                }

                if( !data ){

                    alert('请选中要删除的项');
                    return;
                }

                this.axios.post( url, data ).then(function( res ){

                    t.get_list();
                });

            }

        },

        created:function(){

            this.get_list();

        }

    }
</script>

<style scoped>

</style>